package com.act.web;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.act.domain.SaleManagement;
import com.act.dto.PagerDTO;
import com.act.dto.Response;
import com.act.service.api.ISaleManagementService;
import com.act.util.LoggerUtil;
import com.act.vo.PagerVo;

@RestController
@RequestMapping("sale")
public class SaleManagementController {
	
	@Resource
	private ISaleManagementService saleManagementService ;
	
	private final Logger LOGGER = Logger.getLogger(SaleManagementController.class);	
	
    @RequestMapping(value="/get",method=RequestMethod.POST)
    @ResponseBody
    public Response getAll(@RequestBody PagerDTO pagerDTO){
	   	 try {
	   		 PagerVo<Map> pagerVo=saleManagementService.getAll(pagerDTO);
	         return Response.success(pagerVo);
	     } catch (Exception e) {
	    	 LoggerUtil.error(LOGGER, e);
	     }
	   	 return Response.fail();
    }
    
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ResponseBody
    public Response add(SaleManagement saleManagement) {
    	 try {
    		 saleManagementService.add(saleManagement);
             return Response.success();
         } catch (Exception e) {
        	 LoggerUtil.error(LOGGER, e);
         }
    	 return Response.fail();
    }
    
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ResponseBody
    public Response update(SaleManagement saleManagement) {
    	 try {
    		 saleManagementService.update(saleManagement);
             return Response.success();
         } catch (Exception e) {
        	 LoggerUtil.error(LOGGER, e);
         }
    	 return Response.fail();
    }  
    
    @RequestMapping(value = "/delete/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Response delete(@PathVariable int id) {
    	 try {
    		 saleManagementService.delete(id);
             return Response.success();
         } catch (Exception e) {
        	 LoggerUtil.error(LOGGER, e);
         }
    	 return Response.fail();
    }     
    
    @RequestMapping(value = "/get/{id}",method = RequestMethod.GET)
    @ResponseBody
    public Response getById(@PathVariable int id) {
    	 try {
    		 SaleManagement saleManagement=saleManagementService.getById(id);
             return Response.success(saleManagement);
         } catch (Exception e) {
        	 LoggerUtil.error(LOGGER, e);
         }
    	 return Response.fail();
    }   
}
